<?php

class Login extends Controller {

	//function __construct()
	function Login()
	{
		parent::Controller();
	}

	function index()
        {
             $data['main_content'] = 'login_form';
		$this->load->view('includes/template', $data);
		
	}

           function test(){
                        $this->load->database();
                        echo "connected ";
                        $this->load->model('users_model');
                        echo "model loaded";
                        $query = $this->db->query('SELECT username, password, email FROM User');

            foreach ($query->result() as $row)
            {
                echo $row->username;
                echo $row->password;
                echo $row->email;
            }

            echo 'Total Results: ' . $query->num_rows();

            $this->users_model->list_users();
            echo $result;

             //mysql_connect("2007.ispace.ci.fsu.edu", "dmb07", "msk75t91") or die(mysql_error()) ;
             //mysql_select_db("dmb07_final") or die(mysql_error()) ;

                    }


        function validate_credentials(){

                        $this->load->model('users_model');
                        $query = $this->users_model->validate();

                        if($query) // if the user's credentials validated...
                        {
                                $data = array(
                                        'username' => $this->input->post('username'),
                                        'is_logged_in' => true
                                );
                                $this->session->set_userdata($data);
                                //redirect to admin/member access
                                redirect('home',$data);
                        }
                        else // incorrect username or password
                        {
                                $this->index();
                        }
                }


                function signup() {
                    //$data['main_content'] = 'signup_form';
                    //$this->load->view('includes/template', $data);
                    $this->load->view('signup_form');
                }

                function create_user()
                {
		$this->load->library('form_validation');

		// field name, error message, validation rules
		$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
                $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
		$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[15]');
                $this->form_validation->set_rules('passwordconf', 'Password Confirmation', 'trim|required|matches[password]');



		if($this->form_validation->run() == FALSE)
		{
			$this->load->view('signup_form');
		}

		else
		{
			$this->load->model('users_model');

			if($this->users_model->add_user())
			{
				//$data['main_content'] = 'signup_successful';
				$this->load->view('signup_successful');
			}
			else
			{
				$this->load->view('signup_form');
			}
		}

	}

	function logout()
	{
		$this->session->sess_destroy();
		$this->index();
	}


}

/* End of file form.php */
/* Location: ./system/application/controllers/form.php */